﻿@model IEnumerable<Qcy.Jshj.Web.Models.Link>
@{
    ViewBag.Title = "友情链接管理";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script src="/Scripts/xheditor/xheditor-1.1.14-zh-cn.min.js"></script>
<table id="datalist" class="easyui-datagrid" style="top: 35px; width: auto; height: 630px;"
    data-options="rownumbers:true,singleSelect:true,toolbar:'#tb',url:'/Admin/GetLinks',pagination:true,pageSize:20">
    <thead>
        <tr>
            <th data-options="field:'Name',width:400">公司名称</th>
            <th data-options="field:'Url',width:400">链接地址</th>
            <th data-options="field:'CreationDateString',width:100">更新时间</th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 5px; height: auto">
    <div>
        关键词:
        <input class="easyui-textbox" name="keyword" id="keyword" />
        发布时间 从:
            <input id="datestart" class="easyui-datebox" type="text" style="width: 90px;" readonly="readonly">
        到:
            <input id="dateend" class="easyui-datebox" type="text" style="width: 90px" readonly="readonly">
        <a href="javascript:void(0);" onclick="model.search();" class="easyui-linkbutton" iconcls="icon-search">搜索</a>
        <a href="javascript:void(0);" onclick="model.reset();" class="easyui-linkbutton">重置</a>
    </div>
    <div>
        <a href="javascript:void(0);" onclick="model.add();" class="easyui-linkbutton" iconcls="icon-add" plain="true">新增</a>
        <a href="javascript:void(0);" onclick="model.update();" class="easyui-linkbutton" iconcls="icon-edit" plain="true">修改</a>
        <a href="javascript:void(0);" onclick="model.del();" class="easyui-linkbutton" iconcls="icon-remove" plain="true">删除</a>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('#modelform').form({
            success: function (data) {
                data = eval("(" + data + ")");
                $.messager.alert('提交结果', data.result, 'info', function () {
                    model.load();
                    $('#modelWindow').window('close');
                });
            }
        });
    });

    var model = {
        add: function () { this.showform(); },
        update: function () {
            var selected = this.selected()
            if (selected != null) {
                this.showform();
                $.get('/Admin/GetLink/' + selected.Id, function (data) {
                    $('#modelform').form('load', data);
                });
            } else {
                alert("请先选择一个友情链接");
            }
        },
        del: function () {
            var row = this.selected();
            if (row == null) {
                alert("请至少选择一个友情链接")
                return false;
            }
            $.messager.confirm('删除确认', '确定要删除"' + row.Name + '"吗?', function (r) {
                if (r) {
                    $.post("/Admin/DeleteLink/" + row.Id, function (data) {
                        $.messager.alert('消息', '' + data.msg + '', 'info', function () {
                            model.load();
                        });
                    }, "JSON")
                }
            });
        },
        showform: function () {
            $("#modelWindow").window("open");
        },
        hideform: function () {
            $("#modelWindow").window("close");
        },
        resetform: function () {
            $("#modelform")[0].reset();
        },
        load: function () {
            $('#datalist').datagrid('load', {
                keyword: $('#keyword').val(),
                datestart: $('#datestart').datebox('getValue'),
                dateend: $('#dateend').datebox('getValue')
            });
        },
        search: function () { this.load() },
        selected: function () {
            return $('#datalist').datagrid('getSelected');
        },
        reset: function () {
            $('#keyword').val("");
            $('#datestart').datebox('setValue', '');
            $('#dateend').datebox('setValue', '');
            this.load();
        }
    };
</script>
<div id="modelWindow" class="easyui-window" title="友情链接管理" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width: 700px; height: 500px; padding: 10px;">
    <form id="modelform" method="post" action="/Admin/Link" enctype="multipart/form-data">
        <input type="hidden" name="Id" id="Id" value="0" />
        <table>
            <tr>
                <td class="flabel" style="width: 80px;">公司名称:</td>
                <td>
                    <input class="easyui-validatebox f600" style="width: 260px;" type="text" name="Name" data-options="required:true" /></td>
            </tr>
            <tr>
                <td class="flabel">链接地址:</td>
                <td>
                    <input class="easyui-validatebox f600" style="width: 260px;" type="text" name="Url" data-options="required:true" /></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: right;">
                    <hr />
                    <input type="submit" value="提交" /></td>
            </tr>
        </table>
    </form>
</div>
